package com.bigknow.appstore.server.common;

import com.bigknow.appstore.server.rpc.RPCServer;
import com.bigknow.appstore.common.inf.HandlerInterface;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

public class RPCHandlerBeanPostProcessor implements BeanPostProcessor {

    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        HandlerInterface handlerClass = bean.getClass().getAnnotation(HandlerInterface.class);
        if (handlerClass != null) {
            RPCServer.registerRPCInterface((Class<Object>) handlerClass.value(), bean);
        }
        return bean;
    }

    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }
}